package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StOrder;
import com.ruoyi.system.service.IStOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 食堂订单Controller
 * 
 * @author ruoyi
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/system/order")
public class StOrderController extends BaseController
{
    @Autowired
    private IStOrderService stOrderService;

    /**
     * 查询食堂订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(StOrder stOrder)
    {
        startPage();
        List<StOrder> list = stOrderService.selectStOrderList(stOrder);
        return getDataTable(list);
    }

    /**
     * 导出食堂订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "食堂订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StOrder stOrder)
    {
        List<StOrder> list = stOrderService.selectStOrderList(stOrder);
        ExcelUtil<StOrder> util = new ExcelUtil<StOrder>(StOrder.class);
        util.exportExcel(response, list, "食堂订单数据");
    }

    /**
     * 获取食堂订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(stOrderService.selectStOrderById(id));
    }

    /**
     * 新增食堂订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "食堂订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StOrder stOrder)
    {
        return toAjax(stOrderService.insertStOrder(stOrder));
    }

    /**
     * 修改食堂订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "食堂订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StOrder stOrder)
    {
        return toAjax(stOrderService.updateStOrder(stOrder));
    }

    /**
     * 删除食堂订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "食堂订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(stOrderService.deleteStOrderByIds(ids));
    }
}
